from vector import vector
from mah_timeModule import mah_timer
import rendering
enemyField = []
class enemy:
    def __init__(self,pos,surface,player):
        self.t = mah_timer()
        self.pos = pos
        self.hp = 10
        self.player = player        
        self.body = rendering.r_object(surface,(255,0,0,100),10,10)
        enemyField.append(self)
    def __del__(self):
        print "Enemy down"
    def think(self):
        self.body.draw(self.pos)        
        if self.t.limitFps(1):
            pPos = self.player.returnDir()
            if self.pos.get() != pPos:
                direction = vector(self.pos.get()[0]-pPos[0],self.pos.get()[1]-pPos[1])
                if abs(direction.get()[0]) != 10:
                    if direction.get()[0] > 0:
                        self.pos.sub(vector(10,0))
                    else:
                        self.pos.add(vector(10,0))
                if abs(direction.get()[1]) != 10:
                    if direction.get()[1] > 0:
                        self.pos.sub(vector(0,10))
                    else:
                        self.pos.add(vector(0,10))
    def die(self):                
        for i in range(0,len(enemyField)):
            if enemyField[i] == self:
                enemyField.pop(i)                
                break            
        self.__del__()
        print enemyField
    def get(self):
        return self.pos.get()
